<?php

declare(strict_types=1);

use Phinx\Migration\AbstractMigration;

final class CreateBizGoodsTicketTableMigration extends AbstractMigration
{
    /**
     * Change Method.
     *
     * Write your reversible migrations using this method.
     *
     * More information on writing migrations is available here:
     * https://book.cakephp.org/phinx/0/en/migrations.html#the-change-method
     *
     * Remember to call "create()" or "update()" and NOT "save()" when working
     * with the Table class.
     */
    public function change(): void
    {
        $this->table('biz_goods_ticket', ['id' => false, 'primary_key' => ['id']])
            ->addColumn('id', 'integer', ['identity' => true])
            ->addColumn('goods_id', 'integer', ['null' => true,'default' => 0,'comment' => '商品ID'])
            ->addColumn('biz_id', 'integer', ['null' => true,'default' => 0,'comment' => '商家ID'])
            ->addColumn('order_id', 'integer', ['null' => true,'default' => 0,'comment' => '订单ID'])
            ->addColumn('code', 'string', ['limit' => 16,'null' => true,'comment' => '核销码'])
            ->addColumn('status', 'integer', ['limit' => 1,'null' => true,'default' => 0,'comment' => '状态'])
            ->addColumn('used_at', 'integer', ['null' => true,'limit'=>11,'comment' => '使用时间','default'=>0])
            ->addColumn('created_at', 'integer', ['null' => true,'limit'=>11,'comment' => '创建时间','default'=>0])
            ->addColumn('expired_at', 'integer', ['null' => true,'limit'=>11,'comment' => '过期时间','default'=>0])
            ->addColumn('updated_at', 'integer', ['null' => true,'limit'=>11,'comment' => '更新时间','default'=>0])
            ->addIndex([ 'code'], ['unique' => true])
            ->create();
    }
}
